#include <iostream>
#include<iostream>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void daozhi(int a[][10],int n,int m)
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cout<<a[n-1-j][i]<<" ";
		}
		cout<<endl;
	}
}
void daozhi3(int a[][10],int n,int m)
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cout<<a[j][4-1-i]<<" ";
		}
		cout<<endl;
	}
}
void daozhi2(int a[][10],int n,int m)
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cout<<a[n-1-i][n-1-j]<<" ";
		}
		cout<<endl;
	}
}
int main(int argc, char** argv)
 {
 	int a[10][10];
 	int m,n,i,j;
 	cin>>n>>m;
 	for(i=0;i<n;i++)
 	{
 		for(j=0;j<m;j++)
 		{
 		cin>>a[i][j];		
 	    }
	}
	cout<<endl;
	daozhi(a,n,m);
	cout<<endl;
	daozhi2(a,n,m);
	cout<<endl;
	daozhi3(a,n,m);
	return 0;
}
